//-
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
export class CreateTHREE {
	constructor(container) {
		this.container = container;

		this.createScene();
		this.createCamera();
		this.createRenderer();
		this.createOrbitControlsHelper();
		this.createAxesHelper();
		this.createAmbientLight();
		this.animate();
	}
	createScene() {
		this.scene = new THREE.Scene();
		return this.scene;
	}
	createCamera() {
		this.camera = new THREE.PerspectiveCamera(
			90,
			this.container.offsetWidth / this.container.offsetHeight,
			0.1,
			1000
		);
		this.camera.position.set(0, 0, 100);
		return this.camera;
	}
	createOrbitControlsHelper() {
		this.controls = new OrbitControls(this.camera, this.renderer.domElement);
		this.controls.update();
	}
	createAxesHelper() {
		const axesHelper = new THREE.AxesHelper(200);
		this.scene.add(axesHelper);
	}
	createRenderer() {
		this.renderer = new THREE.WebGLRenderer({
			antialias: true
		});
		this.renderer.setSize(
			this.container.offsetWidth,
			this.container.offsetHeight
		);
		this.container.appendChild(this.renderer.domElement);
		return this.renderer;
	}
	createAmbientLight() {
		const ambimentLight = new THREE.AmbientLight("#ffffff");
		this.scene.add(ambimentLight);
	}
	animate() {
		requestAnimationFrame(this.animate.bind(this));
		this.renderer.render(this.scene, this.camera);
	}
	demo() {
		const geometry = new THREE.BoxGeometry(20, 20, 20);
		const material = new THREE.MeshBasicMaterial({ color: 0xffff00 });
		const mesh = new THREE.Mesh(geometry, material);
		this.scene.add(mesh);
	}
}
